package stu.day25_day32.day31;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.StringJoiner;

public class hw4 {
    List<String> list = new ArrayList<>();
    List<List<String>> alist = new ArrayList<>();
    public void backtrack(int num,int index,int len,String[] str){
        if(index>=len){
            alist.add(new ArrayList<>(list));
        }

        for(int i=num;i<str.length;i++){
            list.add(str[i]);
            backtrack(i+1,index+1,len,str);
            list.removeLast();
        }
    }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] str = sc.nextLine().split(",");
        int len =  Integer.parseInt(sc.nextLine());

        hw4 h = new hw4();
        h.backtrack(0,0,len,str);

        for (List<String> list : h.alist) {
            StringJoiner sj = new StringJoiner(",");
            for (String s : list) {
                sj.add(s);
            }
            System.out.println(sj.toString());
        }

        }
}
